import ajax, { ListResult } from '../ajax';


export function getList(data:any) {
  return ajax.post<ListResult>('/ControlPanels/Organizations/Query', data);
}

export async function getAll() {
  let pdata = {
    page: 1,
    pageSize: 1000,
    queryProperties: new Array<any>()
  };
  let data = await getList(pdata);
  let arr = new Array<any>();
  data.items.map(a => {
    arr.push({
      label: a.organizationName,
      value: a.organizationId
    });
  });
  return arr;
}

export function updateEntity(data:any) {
  if(data.organizationId) {
    return ajax.put<any>('/ControlPanels/Organizations', data);
  } else {
    return ajax.post<any>('/ControlPanels/Organizations', data);
  }
}

export function deleteEntity(id:number) {
  let deleteCommand = {"id": id};
  return ajax.put<any>('/ControlPanels/Organizations/Actions/Delete', deleteCommand);
}